home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 12
/
Mac Magazin and MacEasy Magazine CD - Issue 12.iso
/
Diskette Mac MAGAZIN
/
QuickEditor 3.6 (FAT)
/
Documentation
/
How to write plug-ins
/
Examples
/
Video Effect
/
Tint.c
< prev
next >
Wrap
Text File
|
1995-04-17
|
8KB
|
238 lines
/******************** ***********************/
//
// Tint Plug-in Source Code
//
// Version 0.7d Mathias TSCHOPP
//
//
// Mathias TSCHOPP
// 13 Troupe
// CH-1253 Vandoeuvres
// GENEVA / SWITZERLAND
//
// FAX: (+41 22) 348 33 28
// Internet: mtschopp@perokcity.net.ch (only short mails, no binaries!)
// mtz@medsun.unige.ch
//
/******************** ***********************/
#include "QDOffscreen.h"
#define zGray1 { 0xFFFF, 0xFFFF, 0xFFFF }
#define zGray2 { 0xEEEE, 0xEEEE, 0xEEEE }
#define zGray3 { 0xDDDD, 0xDDDD, 0xDDDD }
#define zGray4 { 0xCCCC, 0xCCCC, 0xCCCC }
#define zGray5 { 0xBBBB, 0xBBBB, 0xBBBB }
#define zGray6 { 0xAAAA, 0xAAAA, 0xAAAA }
#define zGray7 { 0x9999, 0x9999, 0x9999 }
#define zGray8 { 0x8888, 0x8888, 0x8888 }
#define zGray9 { 0x7777, 0x7777, 0x7777 }
#define zGray10 { 0x6666, 0x6666, 0x6666 }
#define zGray11 { 0x5555, 0x5555, 0x5555 }
#define zGray12 { 0x4444, 0x4444, 0x4444 }
#define zGray13 { 0x3333, 0x3333, 0x3333 }
#define zGray14 { 0x2222, 0x2222, 0x2222 }
#define zGray15 { 0x1111, 0x1111, 0x1111 }
typedef struct{
short what;
Point where;
} messageType;
typedef struct{
RGBColor color;
short factor;
} **PrefHand; // This is where local variables are gonna be stored from one call to another
// This ProcInfo descriptor is only for PPC Plug-ins, remove it if you compile for 68k.
ProcInfoType __procinfo = kCStackBased|\
RESULT_SIZE( SIZE_CODE( sizeof(Boolean) ))|\
STACK_ROUTINE_PARAMETER( 1, SIZE_CODE( sizeof( short)))|\
STACK_ROUTINE_PARAMETER( 2, SIZE_CODE( sizeof( GWorldPtr)))|\
STACK_ROUTINE_PARAMETER( 3, SIZE_CODE( sizeof( GWorldPtr)))|\
STACK_ROUTINE_PARAMETER( 4, SIZE_CODE( sizeof( short)))|\
STACK_ROUTINE_PARAMETER( 5, SIZE_CODE( sizeof( Rect*)))|\
STACK_ROUTINE_PARAMETER( 6, SIZE_CODE( sizeof( messageType*)));
Boolean DoProcess(short,GWorldPtr,GWorldPtr,short,Rect *,RGBColor);
void WriteRes(RGBColor,short);
Boolean HiliteButton(Rect);
Boolean main (short i,GWorldPtr GMonde1,GWorldPtr GMonde2,short nbOfFrames,Rect *MoviEBox,messageType *message)
{
Rect theCoo,Etal,Button,Slide,FiltScreen;
short FiltCursor,theHCoo;
CIconHandle slider;
RGBColor whiteRGB = { 0xFFFF, 0xFFFF, 0xFFFF };
RGBColor blackRGB = { 0, 0, 0 };
RGBColor BlueColor={ 0xCCCC, 0xCCCC, 0xFFFF };
GrafPtr savePort;
PrefHand PrefHandle;
RGBColor tintColor;
GWorldPtr currPort;
GDHandle currDev;
Boolean errorFlag=0;
GetGWorld(&currPort,&currDev); //Get current graphic port so you can restore it
SetRect(&Etal,0,0,MoviEBox->right,MoviEBox->bottom);
SetRect(&FiltScreen,463,168,622,287); // Video Effect screen on QuickEditor Video Effect Panel
SetRect(&Slide,321,110+147,426,119+147);// Slide
SetRect(&Button,399,24+147,447,50+147);//Color Button
slider=GetCIcon(134);
GetPort(&savePort); // savePort now contains the address of QuickEditor Window
PrefHandle =(PrefHand) GetResource('fact',128);
FiltCursor=(**PrefHandle).factor; // load parameters that were stored in resource into local variables
tintColor=(**PrefHandle).color;
ReleaseResource((Handle)PrefHandle);
SetGWorld(GMonde1,nil);EraseRect(&Etal);
CopyBits ( (BitMap *) (*(GMonde2->portPixMap)), (BitMap *) (*(GMonde1->portPixMap)), &Etal, &Etal, srcCopy+64, nil);
SetGWorld(currPort,currDev);
if (message->what==-1) {
FiltCursor=10; // Set Default value the first time the plug-in is called
WriteRes(tintColor,FiltCursor);
}
if (message->what==0) {
PicHandle thePict;
Rect Coord;
// This is an update event.
// Let's draw on QuickEditor Screen
thePict=GetPicture(137);
DrawPicture(thePict,&Button);
ReleaseResource((Handle)thePict);
theHCoo=-3+321+7.5*FiltCursor;
if (theHCoo<321) theHCoo=321;
if (theHCoo>417) theHCoo=417;
SetRect(&theCoo,321,110+147,426,119+147);
RGBForeColor(&BlueColor);
PaintRect(&theCoo);
RGBForeColor(&blackRGB);
SetRect(&theCoo,theHCoo,110+147,theHCoo+9,119+147);
PlotCIcon(&theCoo,slider);
RGBForeColor(&blackRGB);RGBBackColor(&whiteRGB);
errorFlag=DoProcess(FiltCursor,GMonde1,GMonde2,nbOfFrames,&Etal,tintColor);
if (errorFlag) return 1;
CopyBits ( (BitMap *) (*(GMonde2->portPixMap)),&((GrafPtr)savePort)->portBits, &Etal, &FiltScreen, srcCopy+64, nil);
}
if (message->what==1) {
// Process event. Let's process the Video Effect
errorFlag=DoProcess(FiltCursor,GMonde1,GMonde2,nbOfFrames,&Etal,tintColor);
if (errorFlag) return 1;
}
if (message->what==2) {
if (PtInRect(message->where,&Slide)) {
Point MouseLoc,MouseLoc2={-1,-1};
// The user clicked on the slider. Let's change values and give the user visual feedback
while (StillDown()) {
GetMouse(&MouseLoc);
if (MouseLoc.h!=MouseLoc2.h) {
FiltCursor=(float)(MouseLoc.h-321)/7.5;
if (FiltCursor<0) FiltCursor=0;
if (FiltCursor>14) FiltCursor=14;
theHCoo=-4+MouseLoc.h;
if (theHCoo<321) theHCoo=321;
if (theHCoo>417) theHCoo=417;
SetRect(&theCoo,321,110+147,426,119+147);
RGBForeColor(&BlueColor);
PaintRect(&theCoo);
RGBForeColor(&blackRGB);
SetRect(&theCoo,theHCoo,110+147,theHCoo+9,119+147);
PlotCIcon(&theCoo,slider);
RGBForeColor(&blackRGB);RGBBackColor(&whiteRGB);
errorFlag=DoProcess(FiltCursor,GMonde1,GMonde2,nbOfFrames,&Etal,tintColor);
if (errorFlag) return 1;
CopyBits ( (BitMap *) (*(GMonde2->portPixMap)),&((GrafPtr)savePort)->portBits, &Etal, &FiltScreen, srcCopy+64, nil);
}
MouseLoc2=MouseLoc;
}
}
if (PtInRect(message->where,&Button)) {
Boolean answer=0;
RGBColor theColor;
Point where={-1,-1};
// The user wants to change the color
if (HiliteButton(Button)) {
answer=GetColor(where,"\pPick a Color:",&tintColor,&theColor);
if (answer) tintColor=theColor;
}
}
// Let's not forget to write the new parameters in the resource fork so
// we can retrieve them the next time the plug-in is called
WriteRes(tintColor,FiltCursor);
}
DisposCIcon(slider);
return 0;
}
Boolean DoProcess(short i,GWorldPtr GMonde1,GWorldPtr GMonde2,short nbOfFrames,Rect *MoviEBox,RGBColor tintColor)
{
RGBColor FadeGrays[15]={zGray15,zGray14,zGray13,zGray12,zGray11,zGray10,zGray9,zGray8,zGray7,zGray6,
zGray5,zGray4,zGray3,zGray2,zGray1};
Rect Etal;
GWorldPtr GMondeMask=nil;
GWorldPtr currPort;
GDHandle currDev;
OSErr err;
RGBColor whiteRGB = { 0xFFFF, 0xFFFF, 0xFFFF };
RGBColor blackRGB = { 0, 0, 0 };
GetGWorld(&currPort,&currDev);
SetRect(&Etal,0,0,MoviEBox->right,MoviEBox->bottom);
err = NewGWorld(&GMondeMask,32, &Etal, nil, nil, 0);
if (!GMondeMask) return 1;
SetGWorld(GMondeMask,nil);
LockPixels (GMondeMask->portPixMap);
EraseRect(&Etal);
RGBForeColor(&FadeGrays[i]);
PaintRect(&Etal);
SetGWorld(GMonde2,nil);
EraseRect(&Etal);
RGBForeColor(&tintColor);
PaintRect(&Etal);
RGBForeColor(&blackRGB);RGBBackColor(&whiteRGB);
SetGWorld(GMonde2,nil);
CopyMask((BitMap *) (*(GMonde1->portPixMap)),(BitMap *) (*(GMondeMask->portPixMap)),
(BitMap *) (*(GMonde2->portPixMap)),&Etal,&Etal,&Etal);
SetGWorld (currPort, currDev);
UnlockPixels(GMondeMask->portPixMap);
DisposeGWorld(GMondeMask);
return 0;
}
void WriteRes(RGBColor theColor,short factor)
{
PrefHand PrefHandle;
PrefHandle =(PrefHand) GetResource('fact',128);
(**PrefHandle).color = theColor;
(**PrefHandle).factor = factor;
ChangedResource((Handle)PrefHandle);
WriteResource((Handle)PrefHandle);
ReleaseResource((Handle)PrefHandle);
}
Boolean HiliteButton(Rect ButtonC)
{
Point MouseLoc;
Boolean isInv=0;
while (StillDown()) {
GetMouse(&MouseLoc);
if (PtInRect(MouseLoc,&ButtonC)&&!isInv) {
InvertRect(&ButtonC);
isInv=1;
}
if (!PtInRect(MouseLoc,&ButtonC)) {
if (isInv) InvertRect(&ButtonC);
isInv=0;
}
}
if (isInv) InvertRect(&ButtonC);
return isInv;
}